﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using StockExcel;
using Newtonsoft.Json;
namespace MarketFunds
{

 
    public class Diff
    {
        public string f1 { get; set; }
        public string f2 { get; set; }
        public string f3 { get; set; }
        public string f4 { get; set; }
        public string f6 { get; set; }
        public string f12 { get; set; }
        public string f13 { get; set; }
        public string f104 { get; set; }
        public string f105 { get; set; }
        public string f106 { get; set; }
    }

    public class Data
    {
        public string total { get; set; }
        public List<Diff> diff { get; set; }
    }

    public class RootObject
    {
        public string rc { get; set; }
        public string rt { get; set; }
        public string svr { get; set; }
        public string lt { get; set; }
        public string full { get; set; }
        public Data data { get; set; }
    }
    class HSJSON
    {
        public RootObject HSRoot = null;
        public string GetPureHSJSON(string strJSON)
        {
            if (strJSON.Trim().Length == 0)
                return strJSON.Trim();
            //找到第一个( ;
            int nFirstPos = strJSON.IndexOf("(");

            int nLastPos = strJSON.LastIndexOf(")");
            string strTemp = strJSON.Substring(nFirstPos + 1, nLastPos - nFirstPos - 1);
            return strTemp;
        }
        public double GetHSTotalDataByJSON(string strJSON)
        {
            RootObject oro = JsonConvert.DeserializeObject<RootObject>(strJSON);
            if (oro.rc != "0")
            {
                Console.WriteLine("No data.");
                return -1;
            }
            this.HSRoot = oro;
            double dTotal = 0;
            for (int i = 0; i < HSRoot.data.diff.Count; i++)
            {
                string f6 = HSRoot.data.diff[i].f6;
                double dF6 = Convert.ToDouble(f6);
                dTotal += dF6;  //F6值代表沪深市的交易量
            }
                
            return dTotal;
        }
    }

    
    static class Program
    {
        public static System.Diagnostics.Process RunningInstance()
        {
            System.Diagnostics.Process current = System.Diagnostics.Process.GetCurrentProcess();
            System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses();
            foreach (System.Diagnostics.Process process in processes) //查找相同名称的进程 
            {
                if (process.Id != current.Id) //忽略当前进程 
                { //确认相同进程的程序运行位置是否一样. 
                    if (System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("/", @"/") == current.MainModule.FileName)
                    { //Return the other process instance. 
                        return process;
                    }
                }
            } //No other instance was found, return null. 
            return null;
        }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            /*
            if (args.Length != 1)            
                return;
            
            if (args[0] != "Volcano1")
                return;
              */                      
           /*
            if (StockExcel.CommonUtil.ApplicationIsRunning("MarketFunds"))
            {
                MessageBox.Show("MarketFunds已经在运行了！");
                System.Environment.Exit(0);                
            }
            */
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            
            Application.Run(new frmMarketFunds2());
           
            
        }
    }
}
